package com.digitalconsulting.phototraveler;

import java.text.DecimalFormat;
import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.digitalconsulting.phototraveler.datalayer.ItemList;
import com.digitalconsulting.phototraveler.datalayer.ItemListDataSource;
import com.digitalconsulting.phototraveler.datalayer.ItemListDataSource.Sort;

public class PhotoTravelerGalleryAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<ItemList> itemLists;
	private LayoutInflater li;

	public PhotoTravelerGalleryAdapter(Context c, LayoutInflater l, ArrayList<ItemList> il) {
		
		ItemListDataSource dc = new ItemListDataSource(c);
		itemLists = il;
		
		mContext = c;
		li = l;
	}

	public int getCount() {
		return itemLists.size();
	}

	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
        
        final ItemList o = itemLists.get(position);

		Bitmap bitmap = BitmapFactory.decodeFile(o.getImagePath());
	
		View v;
		if(convertView==null){
				
			v=li.inflate(R.layout.icon, parent, false);
			
			TextView txtPlace = (TextView)v.findViewById(R.id.txtPlace);
			txtPlace.setText(o.getPlace());
			
			DecimalFormat df = new DecimalFormat("###,##0.00");
			TextView txtPrice = (TextView)v.findViewById(R.id.txtPrice);
			//txtPrice.setText(df.format(o.getPrice()));
			
			ImageView iv = (ImageView)v.findViewById(R.id.image);
			iv.setImageBitmap(bitmap);

		}
		else
		{
			v = convertView;
		}

        return v;
	}

}
